package com.colin.setting.ui;


import com.colin.ColinConstant;
import com.colin.util.PropertiesManager;

import javax.swing.*;
import java.awt.*;

public class DataBaseConfigUI extends JPanel {
    private final JTextField mysqlHostField;
    private final JTextField mysqlPortField;
    private final JTextField databaseField;
    private final JTextField usernameField;
    private final JTextField passwordField;

    public DataBaseConfigUI() {
        setLayout(new GridLayout(14, 2));

        JLabel mysqlPropertiesJLabel = new JLabel("Mysql:");
        mysqlPropertiesJLabel.setFont(new Font("Arial", Font.BOLD, 18));
        mysqlPropertiesJLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(mysqlPropertiesJLabel);

        JLabel mysqlHostLabel = new JLabel("host:");
        mysqlHostField = new JTextField();
        mysqlHostField.setText(PropertiesManager.getString(ColinConstant.MYSQL_HOST));
        mysqlHostLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        mysqlHostField.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(mysqlHostLabel);
        add(mysqlHostField);

        JLabel mysqlPortLabel = new JLabel("port:");
        mysqlPortField = new JTextField();
        mysqlPortField.setText(PropertiesManager.getString(ColinConstant.MYSQL_PORT));
        mysqlPortLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        mysqlPortField.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(mysqlPortLabel);
        add(mysqlPortField);

        JLabel dataBaseLabel = new JLabel("database:");
        databaseField = new JTextField();
        databaseField.setText(PropertiesManager.getString(ColinConstant.MYSQL_DATABASE));
        dataBaseLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        databaseField.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(dataBaseLabel);
        add(databaseField);

        JLabel usernameLabel = new JLabel("username:");
        usernameField = new JTextField();
        usernameField.setText(PropertiesManager.getString(ColinConstant.MYSQL_USER_NAME));
        usernameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        usernameField.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(usernameLabel);
        add(usernameField);

        JLabel passwordLabel = new JLabel("password:");
        passwordField = new JTextField();
        passwordField.setText(PropertiesManager.getString(ColinConstant.MYSQL_PASS_WORD));
        passwordLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        passwordField.setAlignmentX(Component.LEFT_ALIGNMENT);
        add(passwordLabel);
        add(passwordField);
    }

    public String getMysqlHost() {
        return mysqlHostField.getText();
    }

    public String getMysqlPort() {
        return new String(mysqlPortField.getText());
    }

    public String getUsername() {
        return usernameField.getText();
    }
    public String getPassword() {
        return new String(passwordField.getText());
    }
    public String getDatabase() {
        return new String(databaseField.getText());
    }

}

